home *** CD-ROM | disk | FTP | other *** search
/ Aminet 41 / Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso / Aminet / dev / c / libiconv_src.lha / src / big5hkscs.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-07  |  1.8 KB  |  75 lines

  1. /*
  2.  * BIG5HKSCS
  3.  */
  4.  
  5. /*
  6.  * BIG5HKSCS can be downloaded from
  7.  *   http://www.info.gov.hk/digital21/eng/hkscs/download.html
  8.  *   http://www.info.gov.hk/digital21/eng/hkscs/index.html
  9.  *
  10.  * It extends BIG5 (without the rows 0xC6..0xC7) through the ranges
  11.  *
  12.  *   0x{88..8D}{40..7E,A1..FE}      641 characters
  13.  *   0x{8E..A0}{40..7E,A1..FE}     2898 characters
  14.  *   0x{C6..C8}{40..7E,A1..FE}      359 characters
  15.  *   0xF9{D6..FE}                    41 characters
  16.  *   0x{FA..FE}{40..7E,A1..FE}      763 characters
  17.  *
  18.  * It thereby introduces an irreversible mapping
  19.  *   0x8BF8   0x9F9C
  20.  *   0xC074   0x9F9C
  21.  */
  22.  
  23. #include "hkscs.h"
  24.  
  25. static int
  26. big5hkscs_mbtowc (conv_t conv, wchar_t *pwc, const unsigned char *s, int n)
  27. {
  28.   unsigned char c = *s;
  29.   /* Code set 0 (ASCII) */
  30.   if (c < 0x80)
  31.     return ascii_mbtowc(conv,pwc,s,n);
  32.   /* Code set 1 (BIG5 extended) */
  33.   if (c >= 0xa1 && c < 0xff) {
  34.     if (n < 2)
  35.       return RET_TOOFEW(0);
  36.     {
  37.       unsigned char c2 = s[1];
  38.       if ((c2 >= 0x40 && c2 < 0x7f) || (c2 >= 0xa1 && c2 < 0xff)) {
  39.         if (!((c == 0xc6 && c2 >= 0xa1) || c == 0xc7)) {
  40.           int ret = big5_mbtowc(conv,pwc,s,2);
  41.           if (ret != RET_ILSEQ)
  42.             return ret;
  43.         }
  44.       }
  45.     }
  46.   }
  47.   return hkscs_mbtowc(conv,pwc,s,n);
  48. }
  49.  
  50. static int
  51. big5hkscs_wctomb (conv_t conv, unsigned char *r, wchar_t wc, int n)
  52. {
  53.   unsigned char buf[2];
  54.   int ret;
  55.  
  56.   /* Code set 0 (ASCII) */
  57.   ret = ascii_wctomb(conv,r,wc,n);
  58.   if (ret != RET_ILSEQ)
  59.     return ret;
  60.  
  61.   /* Code set 1 (BIG5 extended) */
  62.   ret = big5_wctomb(conv,buf,wc,2);
  63.   if (ret != RET_ILSEQ) {
  64.     if (ret != 2) abort();
  65.     if (!((buf[0] == 0xc6 && buf[1] >= 0xa1) || buf[0] == 0xc7)) {
  66.       if (n < 2)
  67.         return RET_TOOSMALL;
  68.       r[0] = buf[0];
  69.       r[1] = buf[1];
  70.       return 2;
  71.     }
  72.   }
  73.   return hkscs_wctomb(conv,r,wc,n);
  74. }
  75.